var startLogin = false;

function login() {
	checkLogin();
	if($("#message").text() != "") {
		return false;
	}
	$("form:first").submit();
	$("#loginBtn").attr("disabled", "disabled");
}

function checkLogin() {
	if (!startLogin) {
		startLogin = true;
		bindCheck();
	}
	$("#message").text("");
	if ($("#j_code").val() == "") {
		$("#message").text("请输入验证码");
	}
	if ($("#j_password").val() == "") {
		$("#message").text("请输入密码");
	}
	if ($("#j_username").val() == "") {
		$("#message").text("请输入用户名");
	}
	checkMessage();
}

function bindCheck() {
	$("#j_username").bind('blur focus input change propertychange keydown',checkLogin);
	$("#j_password").bind('blur focus input change propertychange keydown',checkLogin);
	$("#j_code").bind('blur focus input change propertychange keydown',checkLogin);
}

function checkMessage() {
	if($("#message").text() != "") {
		$("#message").show();
		$("#browser").hide();
	} else {
		$("#message").hide();
	}
}

$(document).ready(function() {
	$("#loginBtn").bind("click",login);
	$("#j_username").focus();
	$("#j_username,#j_password,#j_code").keypress(function(event) {
		if (event.which=="13") {
			$("#loginBtn").click();
		}
	});
	checkMessage();
});